/*
 * @Description:
 * @Version: 1.0
 * @Author: wenbin
 * @Date: 2021-09-15 11:11:47
 * @LastEditors: wenbin
 * @LastEditTime: 2022-01-12 11:01:59
 * @FilePath: /vite-ts-vue3-test/src/middleware/index.ts
 * Copyright (C) 2021 wenbin. All rights reserved.
 */
import '@/router/routerFilter';
import { createI18n } from 'vue-i18n';
import enElement from 'element-plus/lib/locale/lang/en';
import zhCNElement from 'element-plus/lib/locale/lang/zh-cn';
import localEn from '../common/lang/en';
import localZhCN from '../common/lang/zhCN';
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import magusUI from 'jwb-vue3-ui/packages/index';
import 'jwb-vue3-ui/lib/theme-default/index.css';
import '../mock/index';

const catchUtils: any = magusUI.exportApi.catchUtil;

if (!catchUtils.getLocalItem('language')) {
  catchUtils.setLocalItem('language', 'zh');
}

const i18n = createI18n({
  locale: catchUtils.getLocalItem('language') || 'zh', // 语言标识, 通过切换locale的值来实现语言切换,this.$i18n.locale
  messages: {
    zh: {
      ...magusUI.exportApi.lang.zhCN,
      ...zhCNElement,
      ...localZhCN,
    }, // 中文语言包
    en: {
      ...magusUI.exportApi.lang.en,
      ...enElement,
      ...localEn,
    }, // 英文语言包
  },
  silentTranslationWarn: true,
});

const middleware = {
  ElementPlus,
  magusUI,
  i18n,
};

export default middleware;
